package com.aj.sharepreferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.aj.application.LoveHomeApplication;

public class LoveHomeSharedPreferences {
	private static SharedPreferences loveHomeSharedPreferences;
	private static final String LOVEHOME_SHAREDPREFERNCES_NAME = "lovehome_sharedpreferences";
	private static final String LOVEHOME_WELCOMEGUIDEFLAG_STRING = "lovehome_welcomeguideflag";
	private static final String LOVEHOME_WIFIFLAG_STRING = "lovehome_wififlag";
	private static final String LOVEHOME_GESTUREPASSWORD_STRING = "lovehome_gesturepassword";
	private static final String HOMERELATION_GESTUREPASSWORD_STRING = "homes_relation_gesturepassword";

	private static void getSharedPreferences() {
		if (loveHomeSharedPreferences == null) {
			loveHomeSharedPreferences = LoveHomeApplication.application
					.getSharedPreferences(LOVEHOME_SHAREDPREFERNCES_NAME,
							Context.MODE_PRIVATE);
		}
	}

	private static void closeSharedPreferences() {
		if (loveHomeSharedPreferences != null) {
			loveHomeSharedPreferences = null;
		}
	}

	public static void insertWelcomeGuideFlag(boolean flag) {
		getSharedPreferences();
		Editor editor = loveHomeSharedPreferences.edit();
		editor.putBoolean(LOVEHOME_WELCOMEGUIDEFLAG_STRING, flag);
		editor.commit();
		closeSharedPreferences();
	}

	public static void insertWifiFlag(boolean flag) {
		getSharedPreferences();
		Editor editor = loveHomeSharedPreferences.edit();
		editor.putBoolean(LOVEHOME_WIFIFLAG_STRING, flag);
		editor.commit();
		closeSharedPreferences();
	}

	public static boolean getWifiFlag() {
		getSharedPreferences();
		boolean isFlag = loveHomeSharedPreferences.getBoolean(
				LOVEHOME_WIFIFLAG_STRING, true);
		closeSharedPreferences();
		return isFlag;
	}

	public static boolean getWelcomeGuideFlag() {
		getSharedPreferences();
		boolean isFlag = loveHomeSharedPreferences.getBoolean(
				LOVEHOME_WELCOMEGUIDEFLAG_STRING, false);
		closeSharedPreferences();
		return isFlag;
	}

	public static void insertGesturePassowrd(String password) {
		getSharedPreferences();
		Editor editor = loveHomeSharedPreferences.edit();
		editor.putString(LOVEHOME_GESTUREPASSWORD_STRING, password);
		editor.commit();
		closeSharedPreferences();
	}

	public static String getGesturePassowrd() {
		getSharedPreferences();
		String password = loveHomeSharedPreferences.getString(
				LOVEHOME_GESTUREPASSWORD_STRING, "");
		closeSharedPreferences();
		return password;
	}
	
	
	   public static void insertHomesRelationGesturePassowrd(String password) {
	        getSharedPreferences();
	        Editor editor = loveHomeSharedPreferences.edit();
	        editor.putString(HOMERELATION_GESTUREPASSWORD_STRING, password);
	        editor.commit();
	        closeSharedPreferences();
	    }

	    public static String getHomesRelationGesturePassowrd() {
	        getSharedPreferences();
	        String password = loveHomeSharedPreferences.getString(HOMERELATION_GESTUREPASSWORD_STRING, "");
	        closeSharedPreferences();
	        return password;
	    }
}
